<template>
  <div>
    <van-nav-bar
      :title="$route.meta.title"
      left-text="返回"
      left-arrow
      :fixed="true"
      :placeholder="true"
      @click-left="$router.go(-1)"
      :right-text="auditBtn"
      @click-right="editApply()"
    />
    <div>
      <div class="headerbox">
        <div
          class="header_top"
          :style="{ width: columns.length * 3 + 'rem' }"
          v-if="columns && columns.length != 0"
        >
          <div
            class="header_item"
            v-for="(item, index) in columns"
            :key="index"
            @click="handleClick(index)"
            :class="tabIndex == index ? 'active' : ''"
          >
            <div class="txt">{{ item.number }}</div>
            <div class="txt1">{{ item.bizDate }}</div>
          </div>
        </div>
      </div>

      <div class="carInfo">
        <div class="carInfo_title">金融服务费收款单</div>
        <div class="carInfo_item">收款单编号：{{ dataSource.billNumber }}</div>
        <div class="carInfo_item">收款日期：{{ dataSource.bizDate }}</div>
        <div class="carInfo_item">单据状态：{{ dataSource.billStatus }}</div>
        <div class="carInfo_item">
          金融专员审核人：{{ dataSource.financialAuditor }}
        </div>
        <div class="carInfo_item">展厅：{{ dataSource.showOrgName }}</div>
        <div class="carInfo_item">车架号：{{ dataSource.vinCode }}</div>
        <div class="carInfo_item">
          收款公司：{{ dataSource.receiveCompany }}
        </div>
        <div class="carInfo_item">收款账号：{{ dataSource.receiveBankNo }}</div>
      </div>

      <div class="carInfo">
        <div class="carInfo_title">金融信息</div>
        <div class="carInfo_item">客户：{{ dataSource.customer }}</div>
        <div class="carInfo_item">付款人：{{ dataSource.payPerson }}</div>
        <div class="carInfo_item">
          分期金融机构：{{ dataSource.installmentBank }}
        </div>
        <div class="carInfo_item">
          分期期数：{{ dataSource.installmentPeriod }}
        </div>
        <div class="carInfo_item">贷款金额：{{ dataSource.creditAmount }}</div>

        <div class="carInfo_item flex">
          <div class="carInfo_item_price">
            是否厂家贴息：{{ dataSource.factoryFinance ? '是' : '否' }}
          </div>
          <div class="carInfo_item_price">
            经销商贴息成本：{{ dataSource.interestCost }}
          </div>
        </div>
        <div class="carInfo_item flex">
          <div class="carInfo_item_price">
            收费比例(%)：{{ dataSource.ratio }}
          </div>
          <div class="carInfo_item_price">
            预计金融服务费：{{ dataSource.preAuditAmt }}
          </div>
        </div>
        <div class="carInfo_item flex">
          <div class="carInfo_item_price">
            累计金融服务费收款：{{ dataSource.totalRecvAmt }}
          </div>
          <div class="carInfo_item_price">
            累计收费比率(%)：{{ dataSource.totalRecvRate }}
          </div>
        </div>
      </div>

      <div class="goBack" @click="goBack">返回</div>
      <!-- 审核情况 -->
      <AuditRecord
        :visible="auditVisible"
        :billId="dataSource.billId ? dataSource.billId : detailId"
        @close="auditVisible = false"
      ></AuditRecord>
    </div>
  </div>
</template>

<script>
import sellManageApi from '@/api/sellManageApi'
import AuditRecord from '@/components/AuditRecord'
export default {
  components: {
    AuditRecord,
  },
  data() {
    return {
      active: '',
      detailId: '', // 当前单据ID
      orderId: '', // 当前合同订单ID
      desBosType: '', // 单据类型 desBosType
      columns: [],
      tabIndex: 0,
      dataSource: {
        billId: '', //单据Id
        billNumber: '', //委托单编号
        bizDate: '', //业务日期
        billStatus: '', //单据状态
        financialAuditor: '', //金融专员审核人
        showOrgName: '', //展厅
        vinCode: '', //车架号
        receiveCompany: '', //收款公司
        receiveBankNo: '', //收款账号
        customer: '', //客户
        payPerson: '', //付款人
        installmentBank: '', //分期金融机构
        creditAmount: '', //贷款金额
        installmentPeriod: '', //分期期数
        factoryFinance: '', //是否厂家贴息
        interestCost: '', //经销商贴息成本
        ratio: '', //收费比例
        preAuditAmt: '', //预计金融服务费
        totalRecvAmt: '', //累计金融服务费收款
        totalRecvRate: '', //累计收款比例
      },
      auditBtn: '',
      auditVisible: false,
    }
  },
  mounted() {
    if (this.$route.query) {
      this.detailId = this.$route.query.billId
      this.orderId = this.$route.query.orderId
      this.desBosType = this.$route.query.desBosType
      console.log(this.detailId)
      console.log(this.orderId)
      console.log(this.desBosType)
      this.getList(this.orderId)
    }
  },
  methods: {
    goBack() {
      this.$router.go(-1)
    },
    handleClick(index) {
      this.tabIndex = index
      this.getDetail()
    },
    getDetail() {
      sellManageApi
        .secondHandCarFacade({
          method: 'getFinalServiceDataById', //固定值
          billId: this.columns[this.tabIndex].billId, //单据Id，必填，String
        })
        .then((res) => {
          if (res.code == 1) {
            this.dataSource = res.data
            if (this.dataSource.billStatus != '保存') {
              this.auditBtn = '审批情况'
            }
          }
        })
    },
    getList() {
      // 根据类型ID获取单据列表
      sellManageApi
        .secondHandCarFacade({
          method: 'getDestInfoBySourceIdAndDestBosType', //固定值
          userId: '', //用户ID，必填，String
          orgId: '', //登录组织Id，必填，String
          billId: this.orderId, //单据Id，必填，String
          desBosType: this.desBosType,
        })
        .then((res) => {
          if (res.code == 1) {
            if (res.data.length >= 1) {
              this.columns = res.data
              this.getDetail()
            } else {
              this.$toast.fail('暂无该单据')
            }
          } else {
            this.$toast.fail('暂无该单据')
          }
        })
    },
    editApply() {
      this.auditVisible = true
    },
  },
}
</script>
<style lang="less" scoped>
.headerbox {
  width: 100%;
  overflow-x: auto;
  &::-webkit-scrollbar {
    display: none;
  }
}
.header_top {
  display: flex;
  align-self: center;
  padding: 0.2rem;
  overflow-x: auto;
  // width: 12rem;
  .header_item {
    width: 3rem;
    background: #fff;
    padding: 0.2rem 0.3rem;
    font-size: 0.32rem;
    border-radius: 5px;
    margin-right: 0.2rem;
    .txt {
      margin-bottom: 0.1rem;
    }
    &.active {
      border: 1px solid #ccc;
      box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
    }
  }
}
.carInfo {
  padding: 0.2rem;
  background: #fff;
  margin-bottom: 0.2rem;
  .source {
    padding-left: 0 !important;
    margin-bottom: 0.2rem;
    justify-content: space-between;

    .source_txt {
      font-size: 0.32rem;
    }
  }

  .carInfo_No {
    margin-bottom: 0.3rem;
    .carInfo_No_item {
      border-right: 1px solid #ccc;
      padding-right: 0.1rem;
      margin-right: 0.1rem;
      font-size: 0.32rem;
      color: #333;
      &:last-child {
        border: none;
      }
    }
  }
  .carInfo_item {
    font-size: 0.32rem;
    margin-bottom: 0.1rem;
    color: #333;
    .carInfo_item_price {
      width: 50%;
    }
  }
  .carInfo_title {
    font-size: 0.32rem;
    color: #333;
    margin-bottom: 0.2rem;
    font-weight: bold;
  }
}
.goBack {
  width: 80%;
  background: #2381e6;
  color: #fff;
  font-size: 0.32rem;
  margin: auto;
  border-radius: 5px;
  padding: 0.2rem;
  text-align: center;
  margin-bottom: 0.5rem;
}
.checkbox {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  /deep/ .van-checkbox__label--disabled {
    color: #333;
  }
  /deep/ .van-checkbox__icon--disabled .van-icon {
    background: none;
  }
  .check_item {
    font-size: 0.32rem;
    color: #333;
    width: 33.33%;
  }
}
</style>
